/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Implementation of wxWidgets base class 'MainFrame'
 * \author Antti Maula <antti.maula@tkk.fi>
 * \author wxFormBuilder (Autogenerated base code)
 *
 * $Id: MaCI_AlarmMainFrame.h,v 1.10 2009-04-27 09:23:05 amaula Exp $
 *
 */
#ifndef __MaCI_AlarmMainFrame__
#define __MaCI_AlarmMainFrame__

#include "MaCI_Alarm_GUI.h"
#include "AlarmClient.hpp"
#include "ownutils.h"
#include "Component.hpp"
#include "sync.hpp"
#include "MaCI_AlarmDataTypes.hpp"
#include <vector>
#include <wx/timer.h>

namespace MaCI {
  namespace Alarm {
    class CAlarmClient;
  }
}
namespace gimi {
  class GIMI;
}

// Custom events.
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(MY_EVENT_REFRESHEVENTLIST, -1)
DECLARE_EVENT_TYPE(MY_EVENT_QUESTIONDIALOGEVENT, -1);
END_DECLARE_EVENT_TYPES();

// Forward declare
class MaCI_AlarmQuestionDialog;


/** Implementing MainFrame */
class MaCI_AlarmMainFrame : private gim::CSync,
                            public MainFrame,
                            public Gimbo::CComponent,
                            public MaCI::Alarm::CAlarmClientCallback
{
  DECLARE_EVENT_TABLE();
 public:
  /** Constructor */
  MaCI_AlarmMainFrame( wxWindow* parent );
  virtual ~MaCI_AlarmMainFrame();
  
  bool Initialize(gimi::GIMI *aGimiPtr, int aGimboID, int aReportID);
  void Deinitialize(void);
 protected:
  
protected:
  void OnServiceAssignment(const Gimbo::TServiceAssignmentList &aServiceList);  
  void OnGimboDetach(void);
  void OnAlarmDataEvent(const MaCI::Alarm::CAlarmData &aData, 
                        const unsigned int aDataSequence,
                        MaCI::Alarm::CAlarmClient &aAlarmClient);
  void OnListItemSelected( wxListEvent& event );   
  void OnAlarmMessage(wxCommandEvent &aEvent);
  void OnUpdateStatusBar(wxCommandEvent &aEvent);
  void OnMenuSelection( wxCommandEvent& event );
  void OnEventsDisplayConfMenuItemSelection( wxCommandEvent& event );
  void OnQuitFileMenuItem( wxCommandEvent& event );
  void OnCloseApplicationEvent( wxCloseEvent& event );
  void OnClearEventsMenuItem( wxCommandEvent& event );
  void OnUnansweredQuestionTimeoutUpdateTimer( wxTimerEvent &event );
  void OnYesButtonClick( wxCommandEvent& event );
  void OnNoButtonClick( wxCommandEvent& event );
  void OnAboutMenuSelect( wxCommandEvent& event );
  void OnQuestionDialogEvent(wxCommandEvent &aEvent);
private:
  bool ExecuteQuestionCheckBox(SAlarmInfo &ai);
  bool ConnectServices(void);
  void DisconnectServices(void);
  void RefreshEventList(void); ///< Must NOT be called from outside wxWidgets thread!
  void RequestRefreshEventList(void); ///< Can be called from anywhere.
  void RequestUpdateStatusBar(void);
  bool SaveConfig(void);
  bool LoadConfig(void);
  void UpdateQuestionEntry(SAlarmInfo *ai);

  Gimbo::TServiceAssignmentList iServiceList;
  bool iServiceListUpdated;
  std::vector<MaCI::Alarm::CAlarmClient *> iAlarmClientArray;
  std::list<SAlarmInfo> iAlarmInfoArray;
  gimi::GIMI *iGIMIPtr;

  SEventsDisplayConfiguration iEventsDisplayConfig;

  std::list<MaCI_AlarmQuestionDialog *> iQuestionDialogBoxArray;

  // Unanswered Question box status info
  wxTimer iUnansweredQuestionTimeoutUpdateTimer;
  SAlarmInfo * iUnansweredQuestionActiveEntry;
  
};

#endif // __MaCI_AlarmMainFrame__
